package OOP;

public class SuperArray {
    int dqindex = -1;
    int[] nums;

    public SuperArray() {
        this(3);
    }

    public SuperArray(int rl) {
        nums = new int[rl];
    }

    public void add(int date) {
        dqindex++;
        if (dqindex > nums.length - 1) {
            int[] temp = new int[nums.length * 2];
            for (int i = 0; i < nums.length; i++) {
                temp[i] = nums[i];
            }
            nums = temp;
        }
        nums[dqindex] = date;
    }

    public void del(int index) {
        if (index < 0 || index > nums.length - 1) {
            System.out.println("您删除的下标[" + index + "]不在范围内");
        } else {

            for (int i = index + 1; i < nums.length - 1; i++) {
                nums[i - 1] = nums[i];
            }
            dqindex--;
        }
    }

    public void set(int index, int date) {
        if (index < 0 || index > nums.length - 1) {
            System.out.println("您修改的下标[" + index + "]不在范围内");
        } else {
            nums[index] = date;

        }
    }

    public int select(int index) {
        if (index < 0 || index > nums.length - 1) {
            System.out.println("您查找的下标[" + index + "]不在范围内");
            return -1;
        }
        return nums[index];
    }



    public int size() {
        return dqindex + 1;
    }

    public String ArraytoString() {
        String res = "[";
        for (int i = 0; i <= dqindex; i++) {
            res += nums[i] + ",";
        }
        res = res.substring(0, res.length() - 1) + "]";
        return res;
    }

}
